/*
 * rtpStreamer.h
 *
 *  Created on: Nov 27, 2011
 *      Author: shaohong
 */

#ifndef RTPSTREAMER_H_
#define RTPSTREAMER_H_

#include "PCM_Data_Block.h"
#include "PcmPlayoutBuffer.h"
#include "RtpHeader.h"

#include <stddef.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <stdint.h>
#include <list>
#include <utility>

using namespace std;

/**
 * an RtpStreamer will stream media via RTP to its peer defined by "remoteIP" and "remotePort".
 * an RtpStreamer will maintain its own state and extract data from its play out buffer and send Data over RTP to its peer
 */
namespace nmps {

class RtpStreamer {
public:
	RtpStreamer();
	virtual ~RtpStreamer();
	PcmPlayoutBuffer *getPlayoutBuffer();
	void pause();
	void resume();
	bool isPaused();

	void initialize();

	void sendDataOverRTP(bool muted);

	RtpHeader getRTPHeader();

	void addRecipient(string recipientIP, int recipientPort);
	void removeRecipient(string recpientIP, int recipientPort);
	const list< pair<string, int> > * getRecipientList();

	bool hasRecipient();

	void initSockets();

	void clearAudioPlayoutBuffer();

private:
	PcmPlayoutBuffer *playoutBuffer;
	int timerInterval;
	bool paused;
	int packetSize;
	int unSentDataStartPos;
	PCM_Data_Block *currPcmDataBlock;
	int udpSocketFD;
	RtpHeader header;

	list< pair<string, int> > recipientList;
	list<sockaddr_in> remoteSockets;

	void sendAudioPacket(char *audioPacketData, int packetSize);
};

} /* namespace nmps */

#endif /* RTPSTREAMER_H_ */
